#####Replication File for cross-level ties analysis in,  "Decentralization can Increase Cooperation Among Public Officials"

#Adriana Molina-Garz�n, University of Colorado Boulder, adriana.molinagarzon@colorado.edu
#Tara Grillos, Purdue University, tgrillos@purdue.edu
#Alan Zarychta, University of Chicago, azarychta@uchicago.edu
#Krister P. Andersson, University of Colorado Boulder, Institute of Behavioral Science, krister.andersson@colorado.edu





#Suggested citation for replication data:

#Molina-Garz�n A., Grillos T., Zarychta A., and Andersson K.P., 2020, "Replication Data for: Decentralization can Increase Cooperation Among Public Officials", XXXXXX, Harvard Dataverse, V1, XXXX.  


#Suggested citations for study design and full original data collection:

#Zarychta, A., Andersson, K.P., Root, E. D., Menken, J., & Grillos, T. (2019a). Assessing the impacts of governance reforms on health services delivery: A quasi-experimental, multi-method, and participatory approach. Health Services and Outcomes Research Methodology, 19(4), 241-258. https://doi.org/10.1007/s10742-019-00201-8

#Zarychta, A, Andersson, KP, Root, ED, Menken J, Grillos T. (2019b). Supplemental Appendix for "Assessing the impacts of governance reforms on health services delivery: a quasi-experimental, multi-method, and participatory approach." Health Services and Outcomes Research Methodology, 19(4), https://static-content.springer.com/esm/art%3A10.1007%2Fs10742-019-00201-8/MediaObjects/10742_2019_201_MOESM1_ESM.docx





##### Computing Environment

##R version 3.6.1 (2019-07-05) -- "Action of the Toes"
##Copyright (C) 2019 The R Foundation for Statistical Computing
##Platform: x86_64-w64-mingw32/x64 (64-bit)





##### Packages Needed

install.packages("PACKAGE NAME HERE") #to download packages if needed

library(sandwich)
library(lmtest)
library(zoo)
library(texreg)
library(multiwayvcov)
library(MASS)
library(plyr)
library(Hmisc)





##### Additional Functions


#clustered standard errors

clse.f <- function(dat,fm, cluster){  
  require(sandwich) 
  require(lmtest)  
  not <- attr(fm$model,"na.action") 
  if( ! is.null(not)){   
    cluster <- cluster[-not]    
    dat <- dat[-not,]   
  }
  
  with(dat,{   
    M <- length(unique(cluster))   
    N <- length(cluster)  
    K <- fm$rank  
    dfc <- (M/(M-1))*((N-1)/(N-K))  
    uj <- apply(estfun(fm),2, function(x) tapply(x, cluster, sum));   
    vcovCL <- dfc*sandwich(fm, meat=crossprod(uj)/N)  
    coeftest(fm, vcovCL)   
  }       
  )  
}


#CIs for bar graphs

error.bar <- function(x, y, upper, lower, length=0.1,...){
  if(length(x) != length(y) | length(y) !=length(lower) | length(lower) != length(upper))
    stop("vectors must be same length")
  arrows(x,y+upper, x, y-lower, angle=90, code=3, length=length, ...)
}





##### Global Options

options(scipen=999)
options(digits=6)
setwd("C:/FOLDER LOCATION WHERE DATA FILE IS SAVED GOES HERE/...")





##### Load data file

data <- read.csv("clanalysis_anondata_vAug27.csv")
names(data)





##### Table 4. How Decentralization Influences Cross-level Network Capital


## model proportions by decentralized alone

mod.crosslevel.propknown.base <- glm(net_crosslevel_propnumknown ~ decentralized + offset(log(net_crosslevel_propdenomknown)), family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.propknown.base)
mod.crosslevel.propknown.base.cse <- clse.f(data, mod.crosslevel.propknown.base, data$publicid_muni)
mod.crosslevel.propknown.base.cse 

mod.crosslevel.propfriends.base <- glm(net_crosslevel_propnumfriends ~ decentralized + offset(log(net_crosslevel_propdenomfriends)), family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.propfriends.base)
mod.crosslevel.propfriends.base.cse <- clse.f(data, mod.crosslevel.propfriends.base, data$publicid_muni)
mod.crosslevel.propfriends.base.cse


## model proportions by decentralized plus individual characteristics with participant types

mod.crosslevel.propknown.fullpt <- glm(net_crosslevel_propnumknown ~ decentralized + Mujer + Q2_Educacion + Q1_Edad + Q3_YrsSalud + gen_trust + Participant_C + Participant_G + Participant_R + offset(log(net_crosslevel_propdenomknown)), family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.propknown.fullpt)
mod.crosslevel.propknown.fullpt.cse <- clse.f(data, mod.crosslevel.propknown.fullpt, data$publicid_muni)
mod.crosslevel.propknown.fullpt.cse

mod.crosslevel.propfriends.fullpt <- glm(net_crosslevel_propnumfriends ~ decentralized + Mujer + Q2_Educacion + Q1_Edad + Q3_YrsSalud + gen_trust + Participant_C + Participant_G + Participant_R + offset(log(net_crosslevel_propdenomfriends)), family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.propfriends.fullpt)
mod.crosslevel.propfriends.fullpt.cse <- clse.f(data, mod.crosslevel.propfriends.fullpt, data$publicid_muni)
mod.crosslevel.propfriends.fullpt.cse


#crosslevel ties, binary, player type controls table

texreg(list(mod.crosslevel.propknown.base,
            mod.crosslevel.propknown.fullpt,
            mod.crosslevel.propfriends.base,
            mod.crosslevel.propfriends.fullpt), 
       stars=c(0.01, 0.05, 0.10),
       caption="Explaining Cross-level Network Capital (Prop. Known) by Decentralization",
       dcolumn=FALSE,
       custom.model.names=c("Prop. Known Base", "Prop. Known Fullpt", "Prop. Friends Base", "Prop. Friends Fullpt"),
       custom.coef.names=c("Constant", "Decentralized", "Female", "Education", "Age", "Years Working in Health", "Generalized Trust", "Player HC (Ref: Player M)", "Player AI (Ref: Player M)", "Player R (Ref: Player M)"),
       override.se=list(mod.crosslevel.propknown.base.cse[,2],
                        mod.crosslevel.propknown.fullpt.cse[,2],
                        mod.crosslevel.propfriends.base.cse[,2],
                        mod.crosslevel.propfriends.fullpt.cse[,2]),
       override.pval=list(mod.crosslevel.propknown.base.cse[,4],
                          mod.crosslevel.propknown.fullpt.cse[,4],
                          mod.crosslevel.propfriends.base.cse[,4],
                          mod.crosslevel.propfriends.fullpt.cse[,4]),
       reorder.coef=c(2,3,4,5,6,7,8,9,10,1),
       caption.above=TRUE)





##### Figure 4. Expected Proportion of Strong Cross-level Ties Realized for a Typical Public Servant, Centrally-Administered versus Decentralized Systems


## decent_propfriends_fullpt, full strong ties model from Table 4

mod.crosslevel.propfriends.fullpt <- glm(net_crosslevel_propnumfriends ~ decentralized + Mujer + Q2_Educacion + Q1_Edad + Q3_YrsSalud + gen_trust + Participant_C + Participant_G + Participant_R + offset(log(net_crosslevel_propdenomfriends)), family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.propfriends.fullpt)
mod.crosslevel.propfriends.fullpt.cse <- clse.f(data, mod.crosslevel.propfriends.fullpt, data$publicid_muni)
mod.crosslevel.propfriends.fullpt.cse


## Simulate Coefficients ##
# Seed and number of repetitions
set.seed(19850824)
m <- 100000


# Simulate coefficients from a multivariate normal
betas <- mod.crosslevel.propfriends.fullpt$coef
vcv <- cluster.vcov(mod.crosslevel.propfriends.fullpt, data$publicid_muni)
sim.betas <- mvrnorm(m, betas, vcv)


# Compare simulated coefficients with real results
round(mod.crosslevel.propfriends.fullpt$coef, digits = 2)
round(head(sim.betas, 10), digits = 2)
data.frame(sim.means = apply(sim.betas, 2, mean), betas = betas, sim.sd = apply(sim.betas, 2, sd), se = sqrt(diag(vcv)))   


# Create hypothetical independent variable profiles
decent.data <- data.frame(intercept=1, decentralized=1, Mujer = median(na.omit(data$Mujer)), Q2_Educacion = mean(na.omit(data$Q2_Educacion)), Q1_Edad = mean(na.omit(data$Q1_Edad)), Q3_YrsSalud = mean(na.omit(data$Q3_YrsSalud)), gen_trust = mean(na.omit(data$gen_trust)), Participant_C=1, Participant_G=0, Participant_R=0)

centadmin.data <- data.frame(intercept=1, decentralized=0, Mujer = median(na.omit(data$Mujer)), Q2_Educacion = mean(na.omit(data$Q2_Educacion)), Q1_Edad = mean(na.omit(data$Q1_Edad)), Q3_YrsSalud = mean(na.omit(data$Q3_YrsSalud)), gen_trust = mean(na.omit(data$gen_trust)), Participant_C=1, Participant_G=0, Participant_R=0)


# Compute the expected counts and confidence intervals using the simulated coefficients
ec.sim <- matrix(NA, nrow = m, ncol = 1)

for(i in 1:m){
  ec.sim[i, ] <- exp(as.matrix(decent.data)%*%sim.betas[i, ])
}

pe.decent <- apply(ec.sim, 2, mean)
lo.decent <- apply(ec.sim, 2, quantile, prob = .025)
hi.decent <- apply(ec.sim, 2, quantile, prob = .975)


ec.sim <- matrix(NA, nrow = m, ncol = 1)

for(i in 1:m){
  ec.sim[i, ] <- exp(as.matrix(centadmin.data)%*%sim.betas[i, ])
}

pe.centadmin <- apply(ec.sim, 2, mean)
lo.centadmin <- apply(ec.sim, 2, quantile, prob = .025)
hi.centadmin <- apply(ec.sim, 2, quantile, prob = .975)


# Expected values for central admin and decent

pe.decent
pe.centadmin

admin.pe <- matrix(c(pe.centadmin, pe.decent),2,1,byrow=TRUE)

admin.lo <- matrix(c(lo.centadmin, lo.decent),2,1,byrow=TRUE)
admin.hi <- matrix(c(hi.centadmin, hi.decent),2,1, byrow=TRUE)

admin.lower <- admin.pe-admin.lo
admin.upper <- admin.hi-admin.pe


# Make barplot

par(mar = c(2.3, 4.3, 1, .1))

bplot.admin <- barplot(admin.pe, beside=TRUE, space=0.3, ylim=c(0,0.4), ylab="Expected Prop. of Strong Cross-level Ties Realized", names.arg=c("Centrally-Admin.", "Decentralized"), cex.lab=1.1, cex.names=1.2, col=c("gray75","gray45"), border=c("gray75","gray45"), args.legend=list(x="top", bty="n", horiz=TRUE, border=c(c("gray75","gray45"))))

error.bar(bplot.admin, admin.pe, admin.upper, admin.lower)


dev.off()





##### Table SA7:  Averages of Cross-level Network Variables (all levels)

round(ddply(data, .(decentralized), function(x) data.frame(net_crosslevel_propknown=wtd.mean(x$net_crosslevel_propknown, x$weights_games_full_scaled, na.rm=TRUE))), 2)

round(ddply(data, .(decentralized), function(x) data.frame(net_crosslevel_propfriends=wtd.mean(x$net_crosslevel_propfriends, x$weights_games_full_scaled, na.rm=TRUE))),2)





##### Table SA8.  How Decentralization Influences Cross-level Network Capital, Hours, Player Type Controls


## model HOURS RC by decentralization alone

mod.crosslevel.hoursrcknown.base <- glm(net_crosslevel_hoursrcknown ~ decentralized, family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.hoursrcknown.base)
mod.crosslevel.hoursrcknown.base.cse <- clse.f(data, mod.crosslevel.hoursrcknown.base, data$publicid_muni)
mod.crosslevel.hoursrcknown.base.cse

mod.crosslevel.hoursrcfriends.base <- glm(net_crosslevel_hoursrcfriends ~ decentralized, family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.hoursrcfriends.base)
mod.crosslevel.hoursrcfriends.base.cse <- clse.f(data, mod.crosslevel.hoursrcfriends.base, data$publicid_muni)
mod.crosslevel.hoursrcfriends.base.cse


## model HOURS RC by decentralized plus individual characteristics with participant types

mod.crosslevel.hoursrcknown.fullpt <- glm(net_crosslevel_hoursrcknown ~ decentralized + Mujer + Q2_Educacion + Q1_Edad + Q3_YrsSalud + gen_trust + Participant_C + Participant_G + Participant_R, family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.hoursrcknown.fullpt)
mod.crosslevel.hoursrcknown.fullpt.cse <- clse.f(data, mod.crosslevel.hoursrcknown.fullpt, data$publicid_muni)
mod.crosslevel.hoursrcknown.fullpt.cse 

mod.crosslevel.hoursrcfriends.fullpt <- glm(net_crosslevel_hoursrcfriends ~ decentralized + Mujer + Q2_Educacion + Q1_Edad + Q3_YrsSalud + gen_trust + Participant_C + Participant_G + Participant_R, family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.hoursrcfriends.fullpt)
mod.crosslevel.hoursrcfriends.fullpt.cse <- clse.f(data, mod.crosslevel.hoursrcfriends.fullpt, data$publicid_muni)
mod.crosslevel.hoursrcfriends.fullpt.cse 


#crosslevel ties, hours, player type controls table

texreg(list(mod.crosslevel.hoursrcknown.base,
            mod.crosslevel.hoursrcknown.fullpt,
            mod.crosslevel.hoursrcfriends.base,
            mod.crosslevel.hoursrcfriends.fullpt), 
       stars=c(0.01, 0.05, 0.10),
       caption="Explaining Cross-level Network Capital (Hours) by Decentralization",
       dcolumn=FALSE,
       custom.model.names=c("Hours RC Known Base", "Hours RC Known Full", "Hours RC Friends Base", "Hours RC Friends Full"),
       custom.coef.names=c("Constant", "Decentralized", "Female", "Education", "Age", "Years Working in Health", "Generalized Trust", "Player HC (Ref: Player M)", "Player AI (Ref: Player M)", "Player R (Ref: Player M)"),
       override.se=list(mod.crosslevel.hoursrcknown.base.cse[,2],
                        mod.crosslevel.hoursrcknown.fullpt.cse[,2],
                        mod.crosslevel.hoursrcfriends.base.cse[,2],
                        mod.crosslevel.hoursrcfriends.fullpt.cse[,2]),
       override.pval=list(mod.crosslevel.hoursrcknown.base.cse[,4],
                          mod.crosslevel.hoursrcknown.fullpt.cse[,4],
                          mod.crosslevel.hoursrcfriends.base.cse[,4],
                          mod.crosslevel.hoursrcfriends.fullpt.cse[,4]),
       reorder.coef=c(2,3,4,5,6,7,8,9,10,1),
       caption.above=TRUE)





##### Table SA9.  How Decentralization Influences Cross-level Network Capital, Binary, Role Type Controls


## model proportions by decentralized alone

mod.crosslevel.propknown.base <- glm(net_crosslevel_propnumknown ~ decentralized + offset(log(net_crosslevel_propdenomknown)), family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.propknown.base)
mod.crosslevel.propknown.base.cse <- clse.f(data, mod.crosslevel.propknown.base, data$publicid_muni)
mod.crosslevel.propknown.base.cse 

mod.crosslevel.propfriends.base <- glm(net_crosslevel_propnumfriends ~ decentralized + offset(log(net_crosslevel_propdenomfriends)), family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.propfriends.base)
mod.crosslevel.propfriends.base.cse <- clse.f(data, mod.crosslevel.propfriends.base, data$publicid_muni)
mod.crosslevel.propfriends.base.cse


## model proportions by decentralized plus individual characteristics

mod.crosslevel.propknown.full <- glm(net_crosslevel_propnumknown ~ decentralized + Mujer + Q2_Educacion + Q1_Edad + Q3_YrsSalud + gen_trust + CargoMedico + CargoEnfermero + CargoAlcaldia + CargoPromotor + offset(log(net_crosslevel_propdenomknown)), family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.propknown.full)
mod.crosslevel.propknown.full.cse <- clse.f(data, mod.crosslevel.propknown.full, data$publicid_muni)
mod.crosslevel.propknown.full.cse

mod.crosslevel.propfriends.full <- glm(net_crosslevel_propnumfriends ~ decentralized + Mujer + Q2_Educacion + Q1_Edad + Q3_YrsSalud + gen_trust + CargoMedico + CargoEnfermero + CargoAlcaldia + CargoPromotor + offset(log(net_crosslevel_propdenomfriends)), family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.propfriends.full)
mod.crosslevel.propfriends.full.cse <- clse.f(data, mod.crosslevel.propfriends.full, data$publicid_muni)
mod.crosslevel.propfriends.full.cse


#crosslevel ties, binary, role type controls table

texreg(list(mod.crosslevel.propknown.base,
            mod.crosslevel.propknown.full,
            mod.crosslevel.propfriends.base,
            mod.crosslevel.propfriends.full), 
       stars=c(0.01, 0.05, 0.10),
       caption="Explaining Cross-level Network Capital (Prop. Known) by Decentralization",
       dcolumn=FALSE,
       custom.model.names=c("Prop. Known Base", "Prop. Known Full", "Prop. Friends Base", "Prop. Friends Full"),
       custom.coef.names=c("Constant", "Decentralized", "Female", "Education", "Age", "Years Working in Health", "Generalized Trust", "Doctor", "Nurse", "Municipal Official", "Social Worker"),
       override.se=list(mod.crosslevel.propknown.base.cse[,2],
                        mod.crosslevel.propknown.full.cse[,2],
                        mod.crosslevel.propfriends.base.cse[,2],
                        mod.crosslevel.propfriends.full.cse[,2]),
       override.pval=list(mod.crosslevel.propknown.base.cse[,4],
                          mod.crosslevel.propknown.full.cse[,4],
                          mod.crosslevel.propfriends.base.cse[,4],
                          mod.crosslevel.propfriends.full.cse[,4]),
       reorder.coef=c(2,3,4,5,6,7,8,9,10,11,1),
       caption.above=TRUE)





##### Table SA10.  How Decentralization Influences Cross-level Network Capital, Hours, Role Type Controls


## model proportions by decentralized alone

mod.crosslevel.hoursrcknown.base <- glm(net_crosslevel_hoursrcknown ~ decentralized, family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.hoursrcknown.base)
mod.crosslevel.hoursrcknown.base.cse <- clse.f(data, mod.crosslevel.hoursrcknown.base, data$publicid_muni)
mod.crosslevel.hoursrcknown.base.cse

mod.crosslevel.hoursrcfriends.base <- glm(net_crosslevel_hoursrcfriends ~ decentralized, family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.hoursrcfriends.base)
mod.crosslevel.hoursrcfriends.base.cse <- clse.f(data, mod.crosslevel.hoursrcfriends.base, data$publicid_muni)
mod.crosslevel.hoursrcfriends.base.cse


## model HOURS RC by decentralized plus individual characteristics

mod.crosslevel.hoursrcknown.full <- glm(net_crosslevel_hoursrcknown ~ decentralized + Mujer + Q2_Educacion + Q1_Edad + Q3_YrsSalud + gen_trust + CargoMedico + CargoEnfermero + CargoAlcaldia + CargoPromotor, family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.hoursrcknown.full)
mod.crosslevel.hoursrcknown.full.cse <- clse.f(data, mod.crosslevel.hoursrcknown.full, data$publicid_muni)
mod.crosslevel.hoursrcknown.full.cse 

mod.crosslevel.hoursrcfriends.full <- glm(net_crosslevel_hoursrcfriends ~ decentralized + Mujer + Q2_Educacion + Q1_Edad + Q3_YrsSalud + gen_trust + CargoMedico + CargoEnfermero + CargoAlcaldia + CargoPromotor, family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.hoursrcfriends.full)
mod.crosslevel.hoursrcfriends.full.cse <- clse.f(data, mod.crosslevel.hoursrcfriends.full, data$publicid_muni)
mod.crosslevel.hoursrcfriends.full.cse 


#crosslevel ties, hours, role type controls table

texreg(list(mod.crosslevel.hoursrcknown.base,
            mod.crosslevel.hoursrcknown.full,
            mod.crosslevel.hoursrcfriends.base,
            mod.crosslevel.hoursrcfriends.full), 
       stars=c(0.01, 0.05, 0.10),
       caption="Explaining Cross-level Network Capital (Hours) by Decentralization",
       dcolumn=FALSE,
       custom.model.names=c("Hours RC Known Base", "Hours RC Known Full", "Hours RC Friends Base", "Hours RC Friends Full"),
       custom.coef.names=c("Constant", "Decentralized", "Female", "Education", "Age", "Years Working in Health", "Generalized Trust", "Doctor", "Nurse", "Municipal Official", "Social Worker"),
       override.se=list(mod.crosslevel.hoursrcknown.base.cse[,2],
                        mod.crosslevel.hoursrcknown.full.cse[,2],
                        mod.crosslevel.hoursrcfriends.base.cse[,2],
                        mod.crosslevel.hoursrcfriends.full.cse[,2]),
       override.pval=list(mod.crosslevel.hoursrcknown.base.cse[,4],
                          mod.crosslevel.hoursrcknown.full.cse[,4],
                          mod.crosslevel.hoursrcfriends.base.cse[,4],
                          mod.crosslevel.hoursrcfriends.full.cse[,4]),
       reorder.coef=c(2,3,4,5,6,7,8,9,10,11,1),
       caption.above=TRUE)





##### Table SA 12:  Averages of Cross-level Network Variables (collapsed levels)

round(ddply(data, .(decentralized), function(x) data.frame(net_crosslevel_propknown_col=wtd.mean(x$net_crosslevel_propknown_col, x$weights_games_full_scaled, na.rm=TRUE))), 2)

round(ddply(data, .(decentralized), function(x) data.frame(net_crosslevel_propfriends_col=wtd.mean(x$net_crosslevel_propfriends_col, x$weights_games_full_scaled, na.rm=TRUE))),2)





##### Table SA 13.  How Decentralization Influences Cross-level Network Capital (collapsed levels), Binary, Player Type Controls


## model proportions by decentralized alone

mod.crosslevel.propknown.base <- glm(net_crosslevel_propnumknown_col ~ decentralized + offset(log(net_crosslevel_propdenomknown_col)), family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.propknown.base)
mod.crosslevel.propknown.base.cse <- clse.f(data, mod.crosslevel.propknown.base, data$publicid_muni)
mod.crosslevel.propknown.base.cse 

mod.crosslevel.propfriends.base <- glm(net_crosslevel_propnumfriends_col ~ decentralized + offset(log(net_crosslevel_propdenomfriends_col)), family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.propfriends.base)
mod.crosslevel.propfriends.base.cse <- clse.f(data, mod.crosslevel.propfriends.base, data$publicid_muni)
mod.crosslevel.propfriends.base.cse


## model proportions by decentralized plus individual characteristics with participant types

mod.crosslevel.propknown.fullpt <- glm(net_crosslevel_propnumknown_col ~ decentralized + Mujer + Q2_Educacion + Q1_Edad + Q3_YrsSalud + gen_trust + Participant_C + Participant_G + Participant_R + offset(log(net_crosslevel_propdenomknown_col)), family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.propknown.fullpt)
mod.crosslevel.propknown.fullpt.cse <- clse.f(data, mod.crosslevel.propknown.fullpt, data$publicid_muni)
mod.crosslevel.propknown.fullpt.cse

mod.crosslevel.propfriends.fullpt <- glm(net_crosslevel_propnumfriends_col ~ decentralized + Mujer + Q2_Educacion + Q1_Edad + Q3_YrsSalud + gen_trust + Participant_C + Participant_G + Participant_R + offset(log(net_crosslevel_propdenomfriends_col)), family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.propfriends.fullpt)
mod.crosslevel.propfriends.fullpt.cse <- clse.f(data, mod.crosslevel.propfriends.fullpt, data$publicid_muni)
mod.crosslevel.propfriends.fullpt.cse


#crosslevel ties, binary, player type controls table, collapsed levels

texreg(list(mod.crosslevel.propknown.base,
            mod.crosslevel.propknown.fullpt,
            mod.crosslevel.propfriends.base,
            mod.crosslevel.propfriends.fullpt), 
       stars=c(0.01, 0.05, 0.10),
       caption="Explaining Cross-level Network Capital (Prop. Known), Collapsed Levels, by Decentralization",
       dcolumn=FALSE,
       custom.model.names=c("Prop. Known Base", "Prop. Known Fullpt", "Prop. Friends Base", "Prop. Friends Fullpt"),
       custom.coef.names=c("Constant", "Decentralized", "Female", "Education", "Age", "Years Working in Health", "Generalized Trust", "Player HC (Ref: Player M)", "Player AI (Ref: Player M)", "Player R (Ref: Player M)"),
       override.se=list(mod.crosslevel.propknown.base.cse[,2],
                        mod.crosslevel.propknown.fullpt.cse[,2],
                        mod.crosslevel.propfriends.base.cse[,2],
                        mod.crosslevel.propfriends.fullpt.cse[,2]),
       override.pval=list(mod.crosslevel.propknown.base.cse[,4],
                          mod.crosslevel.propknown.fullpt.cse[,4],
                          mod.crosslevel.propfriends.base.cse[,4],
                          mod.crosslevel.propfriends.fullpt.cse[,4]),
       reorder.coef=c(2,3,4,5,6,7,8,9,10,1),
       caption.above=TRUE)





##### Table SA 14.  How Decentralization Influences Cross-level Network Capital (collapsed levels), Hours, Player Type Controls 


## model HOURS RC by decentralization alone

mod.crosslevel.hoursrcknown.base <- glm(net_crosslevel_hoursrcknown_col ~ decentralized, family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.hoursrcknown.base)
mod.crosslevel.hoursrcknown.base.cse <- clse.f(data, mod.crosslevel.hoursrcknown.base, data$publicid_muni)
mod.crosslevel.hoursrcknown.base.cse

mod.crosslevel.hoursrcfriends.base <- glm(net_crosslevel_hoursrcfriends_col ~ decentralized, family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.hoursrcfriends.base)
mod.crosslevel.hoursrcfriends.base.cse <- clse.f(data, mod.crosslevel.hoursrcfriends.base, data$publicid_muni)
mod.crosslevel.hoursrcfriends.base.cse


## model HOURS RC by decentralized plus individual characteristics with participant types

mod.crosslevel.hoursrcknown.fullpt <- glm(net_crosslevel_hoursrcknown_col ~ decentralized + Mujer + Q2_Educacion + Q1_Edad + Q3_YrsSalud + gen_trust + Participant_C + Participant_G + Participant_R, family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.hoursrcknown.fullpt)
mod.crosslevel.hoursrcknown.fullpt.cse <- clse.f(data, mod.crosslevel.hoursrcknown.fullpt, data$publicid_muni)
mod.crosslevel.hoursrcknown.fullpt.cse 

mod.crosslevel.hoursrcfriends.fullpt <- glm(net_crosslevel_hoursrcfriends_col ~ decentralized + Mujer + Q2_Educacion + Q1_Edad + Q3_YrsSalud + gen_trust + Participant_C + Participant_G + Participant_R, family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.hoursrcfriends.fullpt)
mod.crosslevel.hoursrcfriends.fullpt.cse <- clse.f(data, mod.crosslevel.hoursrcfriends.fullpt, data$publicid_muni)
mod.crosslevel.hoursrcfriends.fullpt.cse 


#crosslevel ties, hours, player type controls table, collapsed levels

texreg(list(mod.crosslevel.hoursrcknown.base,
            mod.crosslevel.hoursrcknown.fullpt,
            mod.crosslevel.hoursrcfriends.base,
            mod.crosslevel.hoursrcfriends.fullpt), 
       stars=c(0.01, 0.05, 0.10),
       caption="Explaining Cross-level Network Capital (Hours), Collapsed Levels, by Decentralization",
       dcolumn=FALSE,
       custom.model.names=c("Hours RC Known Base", "Hours RC Known Full", "Hours RC Friends Base", "Hours RC Friends Full"),
       custom.coef.names=c("Constant", "Decentralized", "Female", "Education", "Age", "Years Working in Health", "Generalized Trust", "Player HC (Ref: Player M)", "Player AI (Ref: Player M)", "Player R (Ref: Player M)"),
       override.se=list(mod.crosslevel.hoursrcknown.base.cse[,2],
                        mod.crosslevel.hoursrcknown.fullpt.cse[,2],
                        mod.crosslevel.hoursrcfriends.base.cse[,2],
                        mod.crosslevel.hoursrcfriends.fullpt.cse[,2]),
       override.pval=list(mod.crosslevel.hoursrcknown.base.cse[,4],
                          mod.crosslevel.hoursrcknown.fullpt.cse[,4],
                          mod.crosslevel.hoursrcfriends.base.cse[,4],
                          mod.crosslevel.hoursrcfriends.fullpt.cse[,4]),
       reorder.coef=c(2,3,4,5,6,7,8,9,10,1),
       caption.above=TRUE)





##### Table SA 15.  How Decentralization Influences Cross-level Network Capital (collapsed levels), Binary, Role Type Controls


## model proportions by decentralized alone

mod.crosslevel.propknown.base <- glm(net_crosslevel_propnumknown_col ~ decentralized + offset(log(net_crosslevel_propdenomknown_col)), family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.propknown.base)
mod.crosslevel.propknown.base.cse <- clse.f(data, mod.crosslevel.propknown.base, data$publicid_muni)
mod.crosslevel.propknown.base.cse 

mod.crosslevel.propfriends.base <- glm(net_crosslevel_propnumfriends_col ~ decentralized + offset(log(net_crosslevel_propdenomfriends_col)), family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.propfriends.base)
mod.crosslevel.propfriends.base.cse <- clse.f(data, mod.crosslevel.propfriends.base, data$publicid_muni)
mod.crosslevel.propfriends.base.cse


## model proportions by decentralized plus individual characteristics

mod.crosslevel.propknown.full <- glm(net_crosslevel_propnumknown_col ~ decentralized + Mujer + Q2_Educacion + Q1_Edad + Q3_YrsSalud + gen_trust + CargoMedico + CargoEnfermero + CargoAlcaldia + CargoPromotor + offset(log(net_crosslevel_propdenomknown_col)), family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.propknown.full)
mod.crosslevel.propknown.full.cse <- clse.f(data, mod.crosslevel.propknown.full, data$publicid_muni)
mod.crosslevel.propknown.full.cse

mod.crosslevel.propfriends.full <- glm(net_crosslevel_propnumfriends_col ~ decentralized + Mujer + Q2_Educacion + Q1_Edad + Q3_YrsSalud + gen_trust + CargoMedico + CargoEnfermero + CargoAlcaldia + CargoPromotor + offset(log(net_crosslevel_propdenomfriends_col)), family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.propfriends.full)
mod.crosslevel.propfriends.full.cse <- clse.f(data, mod.crosslevel.propfriends.full, data$publicid_muni)
mod.crosslevel.propfriends.full.cse


#crosslevel ties, binary, role type controls table, collapsed levels

texreg(list(mod.crosslevel.propknown.base,
            mod.crosslevel.propknown.full,
            mod.crosslevel.propfriends.base,
            mod.crosslevel.propfriends.full), 
       stars=c(0.01, 0.05, 0.10),
       caption="Explaining Cross-level Network Capital (Prop. Known), Collapsed Levels, by Decentralization",
       dcolumn=FALSE,
       custom.model.names=c("Prop. Known Base", "Prop. Known Full", "Prop. Friends Base", "Prop. Friends Full"),
       custom.coef.names=c("Constant", "Decentralized", "Female", "Education", "Age", "Years Working in Health", "Generalized Trust", "Doctor", "Nurse", "Municipal Official", "Social Worker"),
       override.se=list(mod.crosslevel.propknown.base.cse[,2],
                        mod.crosslevel.propknown.full.cse[,2],
                        mod.crosslevel.propfriends.base.cse[,2],
                        mod.crosslevel.propfriends.full.cse[,2]),
       override.pval=list(mod.crosslevel.propknown.base.cse[,4],
                          mod.crosslevel.propknown.full.cse[,4],
                          mod.crosslevel.propfriends.base.cse[,4],
                          mod.crosslevel.propfriends.full.cse[,4]),
       reorder.coef=c(2,3,4,5,6,7,8,9,10,11,1),
       caption.above=TRUE)





##### Table SA 16.  How Decentralization Influences Cross-level Network Capital (collapsed levels), Hours, Player Type Controls


## model proportions by decentralized alone

mod.crosslevel.hoursrcknown.base <- glm(net_crosslevel_hoursrcknown_col ~ decentralized, family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.hoursrcknown.base)
mod.crosslevel.hoursrcknown.base.cse <- clse.f(data, mod.crosslevel.hoursrcknown.base, data$publicid_muni)
mod.crosslevel.hoursrcknown.base.cse

mod.crosslevel.hoursrcfriends.base <- glm(net_crosslevel_hoursrcfriends_col ~ decentralized, family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.hoursrcfriends.base)
mod.crosslevel.hoursrcfriends.base.cse <- clse.f(data, mod.crosslevel.hoursrcfriends.base, data$publicid_muni)
mod.crosslevel.hoursrcfriends.base.cse


## model HOURS RC by decentralized plus individual characteristics

mod.crosslevel.hoursrcknown.full <- glm(net_crosslevel_hoursrcknown_col ~ decentralized + Mujer + Q2_Educacion + Q1_Edad + Q3_YrsSalud + gen_trust + CargoMedico + CargoEnfermero + CargoAlcaldia + CargoPromotor, family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.hoursrcknown.full)
mod.crosslevel.hoursrcknown.full.cse <- clse.f(data, mod.crosslevel.hoursrcknown.full, data$publicid_muni)
mod.crosslevel.hoursrcknown.full.cse 

mod.crosslevel.hoursrcfriends.full <- glm(net_crosslevel_hoursrcfriends_col ~ decentralized + Mujer + Q2_Educacion + Q1_Edad + Q3_YrsSalud + gen_trust + CargoMedico + CargoEnfermero + CargoAlcaldia + CargoPromotor, family="poisson", weights=weights_games_full_scaled, data=data)
summary(mod.crosslevel.hoursrcfriends.full)
mod.crosslevel.hoursrcfriends.full.cse <- clse.f(data, mod.crosslevel.hoursrcfriends.full, data$publicid_muni)
mod.crosslevel.hoursrcfriends.full.cse 


#crosslevel ties, hours, role type controls table, collapsed levels

texreg(list(mod.crosslevel.hoursrcknown.base,
            mod.crosslevel.hoursrcknown.full,
            mod.crosslevel.hoursrcfriends.base,
            mod.crosslevel.hoursrcfriends.full), 
       stars=c(0.01, 0.05, 0.10),
       caption="Explaining Cross-level Network Capital (Hours), Collapsed Levels, by Decentralization",
       dcolumn=FALSE,
       custom.model.names=c("Hours RC Known Base", "Hours RC Known Full", "Hours RC Friends Base", "Hours RC Friends Full"),
       custom.coef.names=c("Constant", "Decentralized", "Female", "Education", "Age", "Years Working in Health", "Generalized Trust", "Doctor", "Nurse", "Municipal Official", "Social Worker"),
       override.se=list(mod.crosslevel.hoursrcknown.base.cse[,2],
                        mod.crosslevel.hoursrcknown.full.cse[,2],
                        mod.crosslevel.hoursrcfriends.base.cse[,2],
                        mod.crosslevel.hoursrcfriends.full.cse[,2]),
       override.pval=list(mod.crosslevel.hoursrcknown.base.cse[,4],
                          mod.crosslevel.hoursrcknown.full.cse[,4],
                          mod.crosslevel.hoursrcfriends.base.cse[,4],
                          mod.crosslevel.hoursrcfriends.full.cse[,4]),
       reorder.coef=c(2,3,4,5,6,7,8,9,10,11,1),
       caption.above=TRUE)





##### END




